import Popup from '../../popup/popup';
import { useState, useEffect } from "react";
import emitter from "../../../utils/event"
import "./gainPopup.css";
function GainPopup() {
    const [show, setShow] = useState(false);
    const [prize,setPrize] = useState({});
    const onClickCloseGainPop = () => {
        setShow(false);
    }
    useEffect(() => {
        const openListener = emitter.addListener('openPrizePopup', (data,_) => {
            setShow(true);
            setPrize(data);
        })
        return () => {
            emitter.removeListener(openListener)
        }
    }, [])
    return (
        <Popup show={show}>
            <div className="pop-gain-box">
                <div className="pop-gain-main">
                    <div className="pop-gain--header">
                        <span className="pop-gain--header__title">
                            {/* {prize.title} */}
                            恭喜中奖
                        </span>
                        <span className="pop-gain--header__closebtn" onClick={onClickCloseGainPop} >
                            <i className="byte-icon byte-icon--close iconfont icon-close">
                            </i>
                        </span>
                    </div>
                    <div className="pop-gain--body">
                        <div className="image">
                            <img src={prize.image} alt=""/>
                        </div>
                        <div className="text">
                            {prize.text}
                        </div>
                        <div className="description">
                            {prize.description}
                        </div>
                    </div>
                    <div className="pop-gain--footer">
                        <div className="pop-gain--footer__btn" onClick={onClickCloseGainPop}>
                            再来一次
                        </div>
                    </div>
                </div>
            </div>
        </Popup>
    );
}
export default GainPopup;